
#ifndef __MEDIA_UDP_SERVER_H__
#define __MEDIA_UDP_SERVE_H__

#include <map>
#include <mutex>
#include <string>
#include <functional>
#include "json.h"
#include "Thread/Thread.h"
#include<unistd.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>



namespace Media{

class MediaUdpServer{
public:
    const int ConnectPort = 2208;
    
public:

	static MediaUdpServer *instance(uint16_t port);

    bool serverSocketInit();

    bool sendData(const char* data, size_t length);
	
private:
	MediaUdpServer(uint16_t port);

	~MediaUdpServer();

	void ThreadProc(Fdt::Thread *thread);


private:
    const uint16_t                                          RECEIVE_LEN = 1024;
    
	static std::map<uint16_t, MediaUdpServer *>             sm_objectMap;

	static std::recursive_mutex 			                sm_mapMutex;

    int                                                     m_svrSockfd = -1;

    bool                                                    m_connetStatus = false;

    uint16_t                                                m_svrPort;

    std::mutex                                              m_connectMutex;

    struct sockaddr_in                                      m_svrSocketInfo;

    struct sockaddr_in                                      m_clientSocketInfo;
	
	Fdt::Thread 						                    m_thread{"MediaUdpServer"};//thread放在最后,保证thread最后构造,最先析构

};

}//namespace Media
#endif


